package com.nbjtjc.safe.api.danger;

import com.nbjtjc.common.validator.ValidatorUtils;
import com.nbjtjc.common.validator.group.DeleteGroup;
import com.nbjtjc.common.validator.group.UpdateGroup;
import com.nbjtjc.safe.annotation.SysLog;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.model.danger.DangerInspectListType;
import com.nbjtjc.safe.service.danger.DangerInspectListTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther guqianbin
 * @date 2018/9/14 14:19
 * 隐患检查项的类型
 **/
@RestController
@RequestMapping("/danger/inspectListType")
@CrossOrigin("*")
public class DangerInspectListTypeController {

    @Autowired
    private DangerInspectListTypeService dangerInspectListTypeService;

    @SysLog("添加隐患类型")
    @RequestMapping(value = "/add", method = {RequestMethod.POST})
    public Result add(DangerInspectListType dangerInspectListType) {
        Result result = new Result();
        result.setData(dangerInspectListTypeService.add(dangerInspectListType));
        return result;
    }

    @SysLog("删除隐患类型")
    @RequestMapping(value = "/delete", method = {RequestMethod.POST})
    public Result delete( DangerInspectListType dangerInspectListType) {
        ValidatorUtils.validateEntity(dangerInspectListType, DeleteGroup.class);
        Result result = new Result();
        if(dangerInspectListTypeService.delete(dangerInspectListType)){
            result.setSuccess(true);
        }else{
            result.setFalse("删除失败");
        }
        return result;
    }

    @SysLog("更新隐患类型")
    @RequestMapping(value = "/update", method = {RequestMethod.POST})
    public Result update( DangerInspectListType dangerInspectListType) {
        ValidatorUtils.validateEntity(dangerInspectListType,UpdateGroup.class);
        Result result = new Result();
        result.setData(dangerInspectListTypeService.update(dangerInspectListType));
        return result;
    }

    @RequestMapping(value = "/find", method = {RequestMethod.POST})
    public Result find( DangerInspectListType dangerInspectListType) {
        Result result = new Result();
        result.setData(dangerInspectListTypeService.find(dangerInspectListType));
        return result;
    }
}
